 //------------Sonic CD Special Setup Script-------------//
//--------Scripted by Christian Whitehead 'The Taxman'--------//
//-------Unpacked By Rubberduckycooly's Script Unpacker-------//

//-------Aliases-------//
#alias 1: TYPE_SPECIALSETUP


sub ObjectMain
	3DScene.NoVertices=0
	3DScene.NoFaces=0
	Oscillation++
	if Oscillation==512
		Oscillation=0
	endif
	if Object[4].Value0>0
		Object[4].Value2++
		if Object[4].Value2==60
			Object[4].Value2=0
			if Object[4].Value1>0
				if Object[4].Value1<6
					PlayStageSfx(7,0)
				endif
				Object[4].Value1--
				if Object[4].Value1<20
					ArrayPos0=Object[4].Value6
					if Object[ArrayPos0].Type!=TypeName[UFO]
						PlayStageSfx(5,0)
						ArrayPos1=ArrayPos0
						ArrayPos1++
						Object[ArrayPos0].Type=TypeName[UFO]
						Object[ArrayPos0].Priority=1
						Object[ArrayPos0].PropertyValue=2
						Object[ArrayPos0].XPos=Object[ArrayPos1].XPos
						Object[ArrayPos0].YPos=Object[ArrayPos1].YPos
					endif
				endif
			else
					PlayStageSfx(7,0)
				Object[30].Type=TypeName[StageFinish]
				if Stage.ActNo==8
					Object[30].State=9
					Object[30].draworder=8
				endif
				Player.ControlMode=-1
			endif
		endif
		if Object[4].Value7>0
			if Object[4].Value7>1
				if Object[4].Value7>20
					TempValue0=Object[4].Value2
					TempValue0&=1
					if Object[4].Value1>0
						Object[4].Value1-=TempValue0
					else
						Object[30].Type=TypeName[StageFinish]
						if Stage.ActNo==8
							Object[30].State=9
							Object[30].draworder=8
						endif
						Player.ControlMode=-1
					endif
				else
					if Object[3].Type!=TypeName[WaterSplash]
						Object[4].Value7=0
					endif
				endif
				Object[4].Value7--
			else
				if Object[3].Type!=TypeName[WaterSplash]
					Object[4].Value7=0
				else
					TempValue0=Object[4].Value2
					TempValue0&=1
					if Object[4].Value1>0
						Object[4].Value1-=TempValue0
					else
						Object[30].Type=TypeName[StageFinish]
						if Stage.ActNo==8
							Object[30].State=9
							Object[30].draworder=8
						endif
						Player.ControlMode=-1
					endif
				endif
			endif
		endif
	endif
endsub


sub ObjectDraw
	TempValue0=0
	TempValue1=Screen[3].DrawListSize
	while TempValue0<TempValue1
		TempValue2=TempValue1
		TempValue2--
		while TempValue2>TempValue0
			TempValue3=TempValue2
			TempValue2--
			GetDrawListEntityRef(ArrayPos0,3,TempValue3)
			GetDrawListEntityRef(ArrayPos1,3,TempValue2)
			if Object[ArrayPos0].Value5>Object[ArrayPos1].Value5
				SetDrawListEntityRef(ArrayPos0,3,TempValue2)
				SetDrawListEntityRef(ArrayPos1,3,TempValue3)
			endif
		loop
		TempValue0++
	loop
endsub


sub ObjectStartup
	if Stage.ListPos==0
		if Options.GameMode==0
			if Player.Score==0
				Options.GameMode=-2
			endif
		endif
	endif
	if Options.GameMode==-2
		if Stage.ListPos==0
			Player.Score=0
			ArrayPos1=Options.NoSaveSlot
			ArrayPos1*=800
			ArrayPos1+=800
			SaveRAM[ArrayPos1]=0
			ArrayPos1++
			SaveRAM[ArrayPos1]=0
			ArrayPos1++
			SaveRAM[ArrayPos1]=0
			ArrayPos1++
			SaveRAM[ArrayPos1]=0
			ArrayPos1++
			SaveRAM[ArrayPos1]=0
		endif
	endif
	LoadSpriteSheet("Special/Objects.gif")
	TileLayer[0].Type=4	
			SetMusicTrack("JP/SpecialStage.ogg",0,1)
			SetMusicTrack("JP/ZoneComplete.ogg",1,0)
	Stage.PauseEnabled=0
	Stage.TimeEnabled=0
	Object[23].Type=TypeName[SpecialSetup]
	Object[23].Priority=1
	Object[23].DrawOrder=2
	ArrayPos0=32
	while ArrayPos0<1056
		if Object[ArrayPos0].Type==TypeName[BlankObject]
			ResetObjectEntity(ArrayPos0,TypeName[BlankObject],0,0,0)
		endif
		ArrayPos0++
	loop
endsub

sub RSDK
	LoadSpriteSheet("Global/Display.gif")
	SetEditorIcon(Icon0,SingleIcon,-16,-16,32,32,1,143)
endsub
